home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / contrib / pdcurs22 / samples / firework.c next >
Encoding:
C/C++ Source or Header  |  1995-01-26  |  5.0 KB  |  171 lines

  1. /*
  2. ***************************************************************************
  3. * This file comprises part of PDCurses. PDCurses is Public Domain software.
  4. * You may use this code for whatever purposes you desire. This software
  5. * is provided AS IS with NO WARRANTY whatsoever.
  6. * Should this software be used in another application, an acknowledgement
  7. * that PDCurses code is used would be appreciated, but is not mandatory.
  8. *
  9. * Any changes which you make to this software which may improve or enhance
  10. * it, should be forwarded to the current maintainer for the benefit of 
  11. * other users.
  12. *
  13. * The only restriction placed on this code is that no distribution of
  14. * modified PDCurses code be made under the PDCurses name, by anyone
  15. * other than the current maintainer.
  16. * See the file maintain.er for details of the current maintainer.
  17. ***************************************************************************
  18. */
  19. #include <stdio.h>
  20. #include <signal.h>
  21. #include <curses.h>
  22. #include <ctype.h>
  23. #include <sys/types.h>
  24. #include <time.h>
  25. #define DELAYSIZE 200
  26.  
  27. #if defined(XCURSES)
  28.     char *XCursesProgramName = "firework";
  29. #endif
  30.  
  31. #ifdef PDCDEBUG
  32. char *rcsid_firework  = "$Id$";
  33. #endif
  34.  
  35. main()
  36. {
  37.        int start,end,row,diff,flag,direction,seed;
  38.        int myrefresh();
  39.        void explode();
  40.  
  41.        initscr();
  42.        nodelay( stdscr, TRUE );
  43.        noecho();
  44.        if (has_colors())
  45.           start_color();
  46.        seed = time((time_t *)0);
  47.        srand(seed);
  48.        while(getch() == ERR)  /* loop until a key is hit */
  49.                {
  50.                 do {
  51.                        start = rand() % (COLS -3);
  52.                        end = rand() % (COLS - 3);
  53.                        start = (start < 2) ? 2 : start;
  54.                        end = (end < 2) ? 2 : end;
  55.                        direction = (start > end) ? -1 : 1;
  56.                        diff = abs(start-end);
  57.                    } while (diff<2 || diff>=LINES-2);
  58.                 attrset(A_NORMAL);
  59.                 for (row=0;row<diff;row++)
  60.                        {
  61.                         mvprintw(LINES - row,start + (row * direction),
  62.                                (direction < 0) ? "\\" : "/");
  63.                         if (flag++)
  64.                                {
  65.                                 myrefresh();
  66.                                 clear();
  67.                                 flag = 0;
  68.                                }
  69.                        }
  70.                if (flag++)
  71.                        {
  72.                         myrefresh();
  73.                         flag = 0;
  74.                        }
  75.                seed = time((time_t *)0);
  76.                srand(seed);
  77.                explode(LINES-row,start+(diff*direction));
  78.                clear();
  79.                myrefresh();
  80.               }
  81.        endwin();
  82.        exit(0);
  83. }
  84. void explode(row,col)
  85. int row,col;
  86. {
  87.        clear();
  88.        mvprintw(row,col,"-");
  89.        myrefresh();
  90.  
  91.        init_pair(1,get_colour(),COLOR_BLACK);
  92.        attrset(COLOR_PAIR(1));
  93.        mvprintw(row-1,col-1," - ");
  94.        mvprintw(row,col-1,"-+-");
  95.        mvprintw(row+1,col-1," - ");
  96.        myrefresh();
  97.  
  98.        init_pair(1,get_colour(),COLOR_BLACK);
  99.        attrset(COLOR_PAIR(1));
  100.        mvprintw(row-2,col-2," --- ");
  101.        mvprintw(row-1,col-2,"-+++-");
  102.        mvprintw(row,  col-2,"-+#+-");
  103.        mvprintw(row+1,col-2,"-+++-");
  104.        mvprintw(row+2,col-2," --- ");
  105.        myrefresh();
  106.  
  107.        init_pair(1,get_colour(),COLOR_BLACK);
  108.        attrset(COLOR_PAIR(1));
  109.        mvprintw(row-2,col-2," +++ ");
  110.        mvprintw(row-1,col-2,"++#++");
  111.        mvprintw(row,  col-2,"+# #+");
  112.        mvprintw(row+1,col-2,"++#++");
  113.        mvprintw(row+2,col-2," +++ ");
  114.        myrefresh();
  115.  
  116.        init_pair(1,get_colour(),COLOR_BLACK);
  117.        attrset(COLOR_PAIR(1));
  118.        mvprintw(row-2,col-2,"  #  ");
  119.        mvprintw(row-1,col-2,"## ##");
  120.        mvprintw(row,  col-2,"#   #");
  121.        mvprintw(row+1,col-2,"## ##");
  122.        mvprintw(row+2,col-2,"  #  ");
  123.        myrefresh();
  124.  
  125.        init_pair(1,get_colour(),COLOR_BLACK);
  126.        attrset(COLOR_PAIR(1));
  127.        mvprintw(row-2,col-2," # # ");
  128.        mvprintw(row-1,col-2,"#   #");
  129.        mvprintw(row,  col-2,"     ");
  130.        mvprintw(row+1,col-2,"#   #");
  131.        mvprintw(row+2,col-2," # # ");
  132.        myrefresh();
  133.        return;
  134. }
  135. int myrefresh()
  136. {
  137.        napms(DELAYSIZE);
  138.        move(LINES-1,COLS-1);
  139.        refresh();
  140. }
  141.  
  142. int get_colour()
  143. {
  144.  int attr, tmp;
  145.  
  146.        attr = (rand() % 8)+1;
  147.  
  148.        if (attr == 1)
  149.           attr = COLOR_RED;  /* use red twice */
  150.        else if (attr == 2)
  151.           attr = COLOR_BLUE;
  152.        else if (attr == 3)
  153.           attr = COLOR_GREEN;
  154.        else if (attr == 4)
  155.           attr = COLOR_CYAN;
  156.        else if (attr == 5)
  157.           attr = COLOR_RED;
  158.        else if (attr == 6)
  159.           attr = COLOR_MAGENTA;
  160.        else if (attr == 7)
  161.           attr = COLOR_YELLOW;
  162.        else if (attr == 8)
  163.           attr = COLOR_WHITE;
  164.  
  165.        tmp = (rand() % 2)+1;
  166.        if (tmp > 1)
  167.           attr |= A_BOLD;
  168.        return(attr);
  169. }
  170.